package demo.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

public class ImagePane extends JPanel
{
    private BufferedImage image = null;
    public ImagePane(){
        this.setPreferredSize(new Dimension(100, 90));
        setBorder(BorderFactory.createLineBorder(Color.black));
    }
    
    public ImagePane(int width, int height){
        this.setPreferredSize(new Dimension(width, height));
        setBorder(BorderFactory.createLineBorder(Color.black));
    }
    
    public void setImage(BufferedImage bi){
        image = bi;
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                repaint();
            }
        });
    }
    
    public BufferedImage getImage(){
        return image;
    }
    
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if(image != null){
            g.drawImage(image, 1, 1,this.getWidth()-2, this.getHeight(), this);
        }
    }

}